﻿namespace EyeOpen.Warehouse.Data.Test
{
	using System;
	using System.Linq;

	using EyeOpen.Warehouse.Data.EntityFramework;
	using EyeOpen.Warehouse.Domain;

	using Microsoft.VisualStudio.TestTools.UnitTesting;

	[TestClass]
	public class WarehouseUnitOfWorkTest
	{
		private readonly Guid id = new Guid("53d47d3c-8391-4947-be15-19899196dacc");
		private const string Name = "Bill";

		[TestMethod]
		public void SaveCustomer()
		{
			using (IWarehouseUnitOfWork uow = new WarehouseUnitOfWork())
			{
				if (uow.Db.Exists())
				{
					uow.Db.Delete();
				}

				uow.Db.Create();

				var customer = 
					new Customer
						{
							Id = this.id,
							Name = Name
						};

				uow.CustomerRepository.Add(customer);

				uow.Commit();
			}

			using (IWarehouseUnitOfWork uow = new WarehouseUnitOfWork())
			{
				var customer = uow.CustomerRepository.Single(c => c.Id == this.id);

				Assert.AreEqual(Name, customer.Name);
			}
		}
	}
}